// packageAd/pages/studyJapan/studyJapan.js
import {
	japanStatusApply
} from '../../api/index.js'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		show: false
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {

	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	},
	submit() {
		japanStatusApply({}).then(res => {
		})
		this.setData({
			show: true
		})
	},
	handleClose() {
		this.setData({
			show: false
		})
	},
	toHome() {
		wx.switchTab({
            url: '/pages/index/index',
        })
	},
	save() {
		wx.createSelectorQuery().select('#canvas')
			.fields({
				node: true,
				size: true
			}).exec(res => {
				// console.log(111, res);
				const canvas = res[0].node
				const ctx = canvas.getContext('2d')
				const dpr = wx.getSystemInfoSync().pixelRatio
				canvas.width = res[0].width * dpr
				canvas.height = res[0].height * dpr
				ctx.scale(dpr, dpr)

				let img = canvas.createImage()
				img.src = 'https://bullet001.oss-cn-shanghai.aliyuncs.com/file/payManagerd87ebaae-1e09-4dcb-83ab-317e32be3d72.png'

				img.onload = async (e) => {
					await ctx.drawImage(img, 0, 0, 158, 158)
					setTimeout(() => {
						wx.canvasToTempFilePath({
							canvas: canvas,
							success: (res) => {
								console.log(123, res);
								wx.saveImageToPhotosAlbum({
									filePath: res.tempFilePath,
									success() {
										wx.showToast({
											title: '成功保存',
											icon: 'none'
										})
									},
									fail() {
										wx.showToast({
											title: '保存失败',
											icon: 'none'
										})
									}
								})
							}
						})
					}, 300);
				}
			})
	}

})